﻿/*
*			专用写入buffer
*/
#pragma once

#include <deque>
#include <boost/thread.hpp>
#include "CxPackageData.h"


//采用STD deque 进行数据存储
using	std::deque;
//boost条件变量
using	boost::condition_variable_any;
using	boost::mutex;


namespace ImitateTansfer
{

	class CxWriteBuffer
	{
	public:
		explicit	CxWriteBuffer(size_t buffersize);
	
		CxWriteBuffer();
	
		~CxWriteBuffer();

		CxPackage*		PopBuffer	();
		void			PushBuffer	(CxPackage *			buffer);

	public:

		//判断控制函数

		bool		ClearAll(){Clear();return true;}

		void		NotifyRead(){PushBuffer(CxPackage::Package("End",3,0,0,0));}
		void		NotifyWirte(){}


	private:

		
		bool		Is_Full(){return	m_buffer.size()==m_capacity;}
		bool		Is_Empty(){return	m_buffer.empty();}

		void		Clear();
	
	private:
		size_t								m_capacity;

		//采用boost条件变量进行控制
		mutex								m_mu;
		condition_variable_any				m_readcond;
		condition_variable_any				m_writecond;

		//采用自定package进行数据压缩后入buffer
		deque<CxPackage *>					m_buffer;
	};


}
